package com.smart.terminal.utils;

import com.google.common.io.CharStreams;
import com.jcraft.jsch.ChannelExec;
import com.smart.terminal.exec.ExecGenericObjectPool;
import lombok.Data;

import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * ftp工具类
 *
 * @author wf
 * @version 1.0.0
 * @since 2022/11/10
 */
@Data
public class ExecUtil {
    /**
     * 连接池
     */
    private ExecGenericObjectPool pool;

    public ExecUtil(ExecGenericObjectPool pool) {
        this.pool = pool;
    }

    /**
     * 捕获cmd输出
     *
     * @return String
     */
    public String getExec() throws Exception {
        ChannelExec channelExec = pool.borrowObject();
        InputStream output = channelExec.getInputStream();
        return CharStreams.toString(new InputStreamReader(output));
    }

}